import sys
from PySide6.QtWidgets import QApplication, QWidget, QToolBar
from PySide6.QtGui import QAction
from PySide6.QtCore import Qt

class ToolbarExample(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(800,600)
        # 创建主窗口和布局
        self.setWindowTitle("工具导航栏")

        tool = QToolBar(self)

        # 创建按钮对象
        f_action = QAction("文件",tool)
        edit_action = QAction("编辑",tool)
        choice_action = QAction("选择",tool)
        see_action = QAction("查看",tool)
        # 设置快捷键: 要使用键盘事件
        f_action.setShortcut(Qt.Key.Key_Comma+Qt.Key.Key_M)
        # 把按钮添加到工具栏上
        tool.addActions([f_action, edit_action,choice_action,see_action])
        

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = ToolbarExample()
    window.show()
    sys.exit(app.exec())
